<?php

namespace App\Models\Application;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Page
 * @package App\Models\Application
 * @version June 20, 2018, 1:47 pm CST
 *
 * @property \Illuminate\Database\Eloquent\Collection applicationPages
 * @property string name
 * @property string descrition
 */
class Page extends Model
{
    use SoftDeletes;

    public $table = 'pages';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'name',
        'descrition',
        'ui',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'name'       => 'string',
        'descrition' => 'string',
        'ui'         => 'string',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'name' => 'required|max:100',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     **/
    public function applications()
    {
        return $this->belongsToMany(\App\Models\Application\Application::class, 'application_pages', 'application_id', 'page_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     * 页面推荐位
     **/
    public function arearecs()
    {
        return $this->hasMany(\App\Models\Application\Arearec::class);
    }
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     **/
    public function layouts()
    {
        return $this->belongsToMany(\App\Models\Application\Layout::class, 'page_layouts', 'page_id', 'layout_id');
    }
}
